package com.last.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.last.entity.Order;
import com.last.entity.PageDTO;
import com.last.entity.PageResult;
import com.last.entity.User;
import com.last.mapper.PersonalMapper;
import com.last.service.PersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PersonalServiceImpl implements PersonalService {
    @Autowired
    private PersonalMapper personalMapper;
    @Override
    public PageResult<Order> userListAllOrder(PageDTO<Order> pageDTO, int userId) {
        IPage<Order> iPage = new Page<>(pageDTO.getPage(),pageDTO.getLimit());
        IPage<Order> page = personalMapper.userListAllOrder(iPage,userId);
        PageResult<Order> result = new PageResult<>();
        result.setData(page.getRecords());
        result.setPages(page.getPages());
        result.setTotal(page.getTotal());
        return result;
    }

    @Override
    public PageResult<User> userListInformation(PageDTO<Order> pageDTO, int userId) {
        IPage<Order> iPage = new Page<>(pageDTO.getPage(),pageDTO.getLimit());
        IPage<User> page = personalMapper.userListInformation(iPage,userId);
        PageResult<User> result = new PageResult<>();
        result.setData(page.getRecords());
        result.setPages(page.getPages());
        result.setTotal(page.getTotal());
        return result;
    }
}
